﻿<%@ Page Language="C#" MasterPageFile="~/Forum.master" AutoEventWireup="true" CodeBehind="SearchResultsPage.aspx.cs" Inherits="Forums.SearchResultsPage" %>
<%@ Register src="UserControls/SearchFunction.ascx" tagname="SearchFunction" tagprefix="uc1" %>
<%@ Register src="UserControls/Menu.ascx" tagname="Menu" tagprefix="uc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="menuContentHolder" runat="server">
    <uc2:Menu ID="Menu1" runat="server" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="searchContentHolder" runat="server">
    <uc1:SearchFunction ID="SearchFunction1" runat="server" />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="mainContentHolder" runat="server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="topic_id" DataSourceID="SearchResultsPart2" 
        AllowPaging="True" >
        <Columns>
            <asp:TemplateField HeaderText="Results">
                <ItemTemplate>
                    <asp:HyperLink ID="HyperLink1" runat="server" 
                        Text='<%# Eval("thread_subject", "{0}") %>'></asp:HyperLink>
                    <br />
                    <asp:HyperLink ID="HyperLink2" runat="server" 
                        Text='<%# Eval("thread_body", "{0}") %>'></asp:HyperLink>
                    <br />
                    <asp:HyperLink ID="HyperLink3" runat="server" 
                        Text='<%# Eval("reply", "{0}") %>'></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
             <asp:TemplateField HeaderText="Posted By">
                <ItemTemplate>
                    <%#Eval("member_name")%>
                    <br />
                    <img src="UserAvatar.aspx?user_id=<%#Eval("user_accnt") %>" alt="N/A" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="date_posted" HeaderText="Date Posted" 
                SortExpression="date_posted" DataFormatString="{0:D}" >
                <ItemStyle HorizontalAlign="Center" />
            </asp:BoundField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SearchResultsPart2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CentForumsDB %>" 
        SelectCommand="SELECT 
	topic.topic_id,
	topic.thread_subject,
	topic.thread_body,
	topic.reply,
	registration.member_name,
	topic.date_posted,
	registration.user_accnt
FROM
	topic INNER JOIN registration ON registration.user_accnt = topic.user_accnt
WHERE
	topic.thread_subject LIKE '%'+@find+'%'
	OR topic.thread_body LIKE '%'+@find+'%'
	OR topic.reply LIKE '%'+@find+'%'
ORDER BY
	topic.date_posted DESC">
        <SelectParameters>
            <asp:QueryStringParameter DefaultValue="" Name="find" QueryStringField="find" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Content>
